<template>
  <div class="makePage">
    <div class="title border-bottom">
      <i class="icon-xiangzuo" @click="returnDetail"></i>
      <span @click="returnDetail">返回贺卡详情</span>
    </div>
    <div class="makePage-box">
      <div class="item">
        <div class="item-box">
          <div class="pic">
            <img v-show="card ===''" src="~common/image/defaultCard.jpg" @click="hint">
            <img v-show="card !==''" :src="card" alt="" @click="jumpCardDetail">
          </div>
          <router-link tag="div" to="/login" class="btn">
            <span>制作我的名片</span>
          </router-link>
        </div>
      </div>
      <div class="item" @click="jumpGreeting">
        <div class="item-box">
          <div class="pic">
            <img src="~common/image/greetingCard.png" alt="">
          </div>
          <div class="btn">
            <span>制作我的贺卡</span>
          </div>
        </div>
      </div>
    </div>

  </div>
</template>

<script>
  import {isTourist} from 'common/js/user'
  import {setTitle} from 'common/js/title'
  import {computePV,recordPictureShare} from 'common/js/statistics'

  export default {
    data() {
      return {
        card: '',
        official: -1,
        sid:''
      }
    },
    mounted() {
      computePV({
        page_type:6
      })
      //判断是否微信内核
      var ua = window.navigator.userAgent.toLowerCase();
      if (window.location.href.indexOf("uid") >  0){
        if (ua.match(/MicroMessenger/i) == 'micromessenger') {
          if (window.location.href.indexOf("goWeChat") === -1) {
            window.location.href = "http://www.6vbuy.com/member/index.php?act=wx_login&op=getSilenceInfo2&com=6vbuy&go=4&id="+this.$route.params.id+"&c_id="+this.$route.params.cid+"&uid="+this.getUrl('uid');
          } else {
            if(window.location.href.indexOf("sid") >  0){
              this.sid = this.getUrl('sid')
            }else{
              this.sid = localStorage.getItem('token')
            }
            if (window.location.href.indexOf("uid") >  0){
              recordPictureShare({
                'receiver_id':this.sid,
                'card_id':this.$route.params.id,
                'type':1
              })
            }
          }
        }
      }

      setTitle('微微晒')
      if (this.$route.params.cid !== "-1") {
        this.card = baseURL + 's=Show/ChooseCCardPictrue/id/' + this.$route.params.cid
      }
      isTourist().then(res => {
        if (res.status === 1) {
          this.official = res.data;
        }
      })
    },
    methods: {
      getUrl(para) {
        var paraArr = location.search.substring(1).split('&');
        for (var i = 0; i < paraArr.length; i++) {
          if (para == paraArr[i].split('=')[0]) {
            return paraArr[i].split('=')[1];
          }
        }
        return '';
      },
      //返回详情
      returnDetail() {
        this.$router.push('/greetingDetail/' + this.$route.params.id + '/' + this.$route.params.cid)
      },
      //默认名片
      hint() {
        this.$dialog.confirm({
          title: ' ',
          mes: '这家伙很懒，没有填写名片信息，如果你想制作名片，请点击确定',
          opts: () => {
            this.$router.push('/login')
          }
        });
      },
      //跳转制作贺卡
      jumpGreeting() {
        if (this.official !== 1 && this.official !== 2) {
          this.$router.push('/login');
        } else {
          this.$router.push('/greetingTitle')
        }
      },
      //跳转到名片详情
      jumpCardDetail() {
        this.$router.push('/business/' + this.$route.params.cid)
      },
    }

  }
</script>

<style scoped lang="stylus" rel="stylesheet/stylus">
  @import "~common/stylus/variable"
  .title
    position: relative;
    height: 1.5rem;
    line-height: 1.5rem
    font-size: .55rem;
    color: $color-title;
    background: $background;
    z-index: 99;
    padding-left: 1.3rem;
    i
      position: absolute;
      top: 0;
      left: .5rem;
      line-height: 1.5rem;
      font-size: .6rem;
      color: $color-l-z;
    span
      font-size: .43rem;

  .makePage
    min-height: 100%;
    background: #f65ecb;
    background: -webkit-linear-gradient(-300deg, #f65ecb, #9366f1);
    .makePage-box
      padding: .5rem;
    .item
      position: relative;
      margin-bottom: .6rem;
      border-radius: .26rem;
      background: $background-p-i;
      padding: .3rem;
      .pic
        width: 100%;
        text-align: center;
        margin-bottom:.4rem;
      img
        width: 100%;
      .btn
        text-align:center;
        color:$color;
        span
          background: $background-p-btn;
          display :inline-block;
          width: 3.2rem;
          line-height: .85rem;
          border-radius: .425rem;
          font-size .32rem;
        i
          font-size: .27rem;
      .amount
        position: absolute;
        top: .47rem;
        right: .47rem;
        color: $color;
        font-size: .3rem;

</style>
